﻿
Partial Class Geo_Controls_Login
    Inherits MyUI.UserControlBaseApp

    Const LoginPage = "~/Site/Login.aspx"
    Const MainPage = "~/"


    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load

        If UI.Page.GetValue("r") <> "" Then
            UI.Page.RedirectTopJS(Me.ResolveClientUrl(LoginPage))
        End If


        If Not Me.Page.IsPostBack Then
            ViewUser()
        End If

    End Sub

    Protected Sub BtnLogin_Click(sender As Object, e As System.EventArgs) Handles BtnLogin.Click
        If Me.Page.IsValid Then
            Dim au = New MyUI.AuthUsers()

            au.LogIn(Me.TxtEmail.Text, Me.TxtPass.Text, Me.CheckBoxricordami.Checked)
            If Not (au.IsAuthenticated) Then
                LblErroreIns.Text = "Errore inserimento dati"
                LblErroreIns.Visible = True

            End If

            ViewUser()
        End If

    End Sub
    Private Sub ViewUser()

        Dim au = New MyUI.AuthUsers()

        If (au.IsAuthenticated) Then

            Response.Redirect(MainPage)

            'Dim CurrUser = MyApp.Session.GetUser
            'LblUtente.Text = "Utente_" & CurrUser.Name
            'LblEmail.Text = CurrUser.Email
            'PnlLoggato.Visible = True
            'PnlNonLoggato.Visible = False
        Else
            'Label1.Text = "No utente"
            PnlNonLoggato.Visible = True
            PnlLoggato.Visible = False
        End If

    End Sub

    Protected Sub BtnLogout_Click(sender As Object, e As System.EventArgs) Handles BtnLogout.Click
        Dim au = New MyUI.AuthUsers()
        au.LogOut()
        Response.Redirect("~/")

    End Sub
End Class
